//获取[min,max]随机数
export function random(min,max) {
    return Math.max(Math.floor(Math.random()*max + 1),min)
}


//将指定歌曲插入指定列表开头
export function push(list,index) {
    let ret = [...list]
    ret.unshift(ret.splice(index,1)[0])
    return ret
}


export function contain(list,song) {
   return list.findIndex(item => item.id === song.id) > -1
}

export function findSong(list,song) {
    return list.findIndex(item => item.id === song.id)
}

//添加歌曲到指定列表
export function add(list,song) {
    if(!contain(list,song))
        list.unshift(song)
    else {
        let index = findSong(list,song)
        list.unshift(list.splice(index,1)[0])
    }
}
